<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" width="85%" destroy-on-close @closed="$emit('closed')" align-center>
        <el-container>
            <el-header>
                <div class="left-panel">
                    <!-- <el-button type="primary" @click="back">确定</el-button> -->
                    <!-- <el-button type="primary" icon="el-icon-plus" v-auth="'goods.add'" @click="add">新增</el-button> -->
                </div>
                <div class="right-panel">
                    <div class="right-panel-search">
                        <el-input v-model="search.production_code" placeholder="生产单编号" clearable @keyup.enter="upsearch"></el-input>
                        <el-select v-model="search.level" placeholder="请选择" clearable>
                            <el-option label="正常" :value="1"/>
                            <el-option label="加急" :value="2"/>
                            <el-option label="延期" :value="3"/>
                        </el-select>
                        <el-input v-model="search.create_time" placeholder="创建时间" clearable @keyup.enter="upsearch"></el-input>
                        <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
                        <el-button type="primary" icon="el-icon-refresh" @click="refresh"></el-button>
                    </div>
                </div>
            </el-header>
            <el-main class="nopadding">
                <scTable ref="table" row-key="id" :apiObj="apiObj" highlight-current-row @row-click="selectionChange" stripe remoteSort remoteFilter border height="650" :params="query">
                    <!-- <el-table-column type="selection" width="50" reserve-selection align="center"></el-table-column> -->
                    <el-table-column type="index" label="序号" fixed align="center" width="50"></el-table-column>
                    <el-table-column label="生产单号" prop="production_code" align="center"></el-table-column>
                    <el-table-column label="销售编号" prop="contract.contract_code" align="center"></el-table-column>
                    <el-table-column label="开单日期" prop="open_date" align="center"></el-table-column>
                    <el-table-column label="交货日期" prop="over_date" align="center"></el-table-column>
                    <el-table-column label="优先级" prop="level" align="center">
                        <template #default="scope">
                            <el-tag :type="scope.row.level == 1 ? 'primary' : scope.row.level == 2 ? 'danger' : 'warning'">{{scope.row.level == 1 ? '正常' : scope.row.level == 2 ? '加急' : '延期'}}</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column label="生产数量" prop="number_all" align="center"></el-table-column>
                    <el-table-column label="入库数量" prop="enter_number_all" align="center"></el-table-column>
                    <el-table-column label="发货数量" prop="deliver_number_all" align="center"></el-table-column>
                    <el-table-column label="制单时间" prop="create_time" align="center"></el-table-column>
                    <el-table-column label="备注" prop="remark" align="center"></el-table-column>
                </scTable>
            </el-main>
        </el-container>
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
    props:{
        query: { type: Object, default: () => ({}) },
    },
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '选择销售',
				edit: '编辑销售',
				show: '查看'
			},
			visible: false,
			isSaveing: false,
			apiObj: this.$API.production.plan.list,
			selection: [],
			search: {
				production_code: null,
                level:null,
                create_time:null,
			},
		}
	},
	mounted() {
	},
	methods: {
		// 显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
        // 选择事件
        selectionChange(selection) {
            this.$emit('success', selection)
            this.visible = false;
		},
        // 选中返回
        back(){
            this.$emit('success', this.selection,this.type)
            this.visible = false;
        },
        //搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
        refresh(){
            for (const key in this.search) {
                this.search[key] = null;
            }
            this.$refs.table.upData(this.search)
        },
	}
}
</script>

<style></style>
